package com.yuandian.management.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.po.ConfMpReturnCodeParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.api.management.entity.ConfMpReturnCode;
import com.yuandian.management.service.ConfMpReturnCodeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 中台监控-返回码配置表-Controller
 * @author zfsn
 * @date 2023-4-23
 */
@Api(tags = "中台监控-返回码配置")
@RestController
@RequestMapping("/mp/returnCode")
public class ConfMpReturnCodeController {

	@Autowired
	private ConfMpReturnCodeService confMpReturnCodeService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键查询", notes = "通过主键查询返回码配置，支持批量查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@GetMapping("/queryByIds/{ids}")
	public R<List<ConfMpReturnCode>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confMpReturnCodeService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param params 中台监控-返回码配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current", value = "当前页", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "size", value = "每页条数", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "orders", value = "排序方式", paramType = "body", required = false, dataType = "OrderItem", dataTypeClass = OrderItem.class, allowMultiple = true),
			@ApiImplicitParam(name = "serviceId", value = "所属服务id", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "type", value = "返回码类型", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "name", value = "返回码名称", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "status", value = "返回码状态", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)
	})
	@PostMapping("/page")
	public R<Page<ConfMpReturnCode>> page(@ApiIgnore @RequestBody ConfMpReturnCodeParams params) {
		return confMpReturnCodeService.page(params);
	}

	/**
	 * 新增数据
	 * @param params 中台监控-返回码配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增返回码", notes = "新增返回码配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "serviceId", value = "所属服务id", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "type", value = "返回码类型", paramType = "body", required = true, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "name", value = "返回码名称", paramType = "body", required = true, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "value", value = "返回码值", paramType = "body", required = true, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "status", value = "返回码状态", paramType = "body", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@PostMapping("/save")
	public R<Boolean> save(@ApiIgnore @RequestBody ConfMpReturnCodeParams params) {
		return confMpReturnCodeService.saveWrap(params);
	}

	/**
	 * 通过主键更新数据
	 * @param params 中台监控-返回码配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键更新", notes = "通过主键更新返回码配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "主键", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "serviceId", value = "所属服务id", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "type", value = "返回码类型", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "name", value = "返回码名称", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "value", value = "返回码值", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "status", value = "返回码状态", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)
	})
	@PutMapping("/updateById")
	public R<Boolean> updateById(@ApiIgnore @RequestBody ConfMpReturnCodeParams params) {
		return confMpReturnCodeService.updateByIdWrap(params);
	}

	/**
	 * 通过主键删除数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键删除", notes = "通过主键删除返回码配置，支持批量删除")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@DeleteMapping("/removeByIds/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> idList) {
		return confMpReturnCodeService.removeByIdsWrap(idList);
	}
}